package context;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.List;

import beans.Information;

import replication.Replicator;

import javolution.util.FastList;

public class ContextManager extends Thread{

	private FastList<Serializable>FileBA;
	private FastList<Serializable>FileLV;
	private FastList<Serializable>FileMY;
	private FastList<Serializable>FileNC;
	
	private Replicator replicateur;
	
	public ContextManager() {
		// TODO Auto-generated constructor stub
		FileBA=new FastList<Serializable>();
		FileLV=new FastList<Serializable>();
		FileMY=new FastList<Serializable>();
		FileNC=new FastList<Serializable>();
		replicateur=new Replicator();
	}
	
	public void run(){
		while(true){
			ChangeContext();
			replicateur.replicate();
		}
	}

	void ChangeContext(){
		try {
			sleep(2000);
			FileBA=new FastList<Serializable>();
			FileBA.add(new Information());
			FileBA.add(new Information());
			
			FileLV=new FastList<Serializable>();
			FileLV.add(new Information());
			FileLV.add(new Information());
			
			FileMY=new FastList<Serializable>();
			FileMY.add(new Information());
			FileMY.add(new Information());
			List<String>hosts=new ArrayList<>();
			hosts.add("localhost");
			
			FileNC=new FastList<Serializable>();
			FileMY.add(new Information());
			FileMY.add(new Information());
			
			
			replicateur.setFileBA(FileBA);
			replicateur.setFileLV(FileLV);
			replicateur.setFileMY(FileMY);
			replicateur.setFileNC(FileMY);
			
			
			HostProvider hostProvider=new HostProvider();
			hostProvider.setListHosts(hosts);
			
			replicateur.setListHosts(hosts);
			
			
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
	}

	public void SetContext(FastList<Serializable> fileBA2,
			FastList<Serializable> fileLV2, FastList<Serializable> fileMY2,
			FastList<Serializable> fileNC2) {
		// TODO Auto-generated method stub
		FileBA=fileBA2;
		FileLV=fileLV2;
		FileMY=fileMY2;
		FileNC=fileNC2;
	}
	

}
